package org.ykhl.zheer.adaptors;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.tempuri.IHisApplay;
import org.ykhl.interfaces.commons.AdapterInterface;
import org.ykhl.model.RetInfo;
import org.ykhl.service.ConvertService;

import javax.xml.ws.Holder;
import java.util.Map;

/**
 * 院内返回
 */
public class Hishospital implements AdapterInterface {

    private static final Logger LOG = LoggerFactory.getLogger(Hishospital.class);
    private RetInfo retInfo = new RetInfo();
    private IHisApplay apply =null;



    public  String getHosMessage(Map<String, Object> params){

        //调用HIS院内系统
        String tradeType = params.get("tradeType").toString();
        String tradeMsg =params.get("requestParam").toString();
        IHisApplay apply = (IHisApplay) params.get("apply");
        String tradeMsgOutVal = "";
        Holder<String> tradeMsgOut = new Holder<String>(tradeMsgOutVal);
        Holder<Integer> runServiceResult = new Holder<Integer>();
        apply.runService(tradeType, tradeMsg, tradeMsgOut, runServiceResult);
        String resp = tradeMsgOut.value;

        LOG.debug(" Receiver form His webservice  - tradeType: " + tradeType );
        LOG.debug(" Receiver form His webservice  -response Message size:" + resp.length());
        return resp;

    }

    /**
     * 根据模版进行转换
     * param.put("fid",fid);
     *param.put("oriMsgBody" ,oriMsgBody);
     * param.put("xslContent" ,xslContent);
     *param.put("key" ,key);
     * @param params
     * @return
     */

    public RetInfo trans(Map<String, Object > params){

        Object ob =   params.get("convertService");
        retInfo = ((ConvertService)ob).defaultConversion(params.get("oriMsgBody").toString(),params.get("xslContent").toString(),params.get("key").toString());
        LOG.debug("hospital retInfo  Content:" + retInfo.getContent().length()+", RetCode :" + retInfo.getRetCode());

        return retInfo;
    }

}
